#include <iostream>

class Complex
{
public:
    Complex():real(0),vir(0){}    //初始化
    Complex(int real, int vir):real(real),vir(vir){}
    void show()
    {
        std::cout<<real<<"+"<<vir<<"i"<<std::endl;
    }

    Complex(const Complex &c)
    {
        std::cout<<"拷贝构造"<<std::endl;
        real = c.real;
        vir = c.vir;
    }

    Complex operator+(const Complex& c)
    {
        Complex result;
        result.real =this->real + c.real;  //私有有一个参数
        result.vir = this->vir + c.vir;
        return result;   //返回的是右值，直接把result内存拿过来
                            //不会发生拷贝，，返回是左值就是拷贝
    }
    Complex operator-(const Complex& c)
    {
        Complex result;
        result.real =this->real - c.real;  //私有有一个参数
        result.vir = this->vir - c.vir;
        return result;
    }
    //前置++
    Complex& operator++()  //返回引用，减少一次拷贝
    {
        real++;
        vir++;
        return *this;   //取当前对象的表达--对象本身
                        //没有销毁，所以是左值
    }
    //a++给值，++a给a变量

    //后置++
    //a++   后面是空，需要占位数(int)占空
    Complex operator++(int)
    {
        Complex result = *this;
        real++;    //后++
        vir++;
        return result;   //现在为局部变量为右值
    }
    friend std::ostream& operator<<(std::ostream& os,const Complex& c);
    friend std::istream& operator>>(std::istream& initstate_r,Complex &c);
private:
    int real;
    int vir;
};

std::ostream& operator<<(std::ostream& os,const Complex& c)   //全局重载
{
    os<<c.real<<"+"<<c.vir<<"i"<<std::endl;
    return os;
}
std::istream& operator>>(std::istream& is,Complex &c)
{
    is>>c.real>>c.vir;
    return is;
}

int main()
{
    // Complex c1(1,2);
    // Complex c2(2,3);
    // c1.show();
    // c2.show();
    
    // //本质是Complex c = c2.operator-(c1);
    // // Complex c = c2 - c1;
    // // c.show();
    // // Complex &c = ++c1;
    // // c.show();
    
    // Complex c = c1++;  //AVO优化，返回的是右值，是将亡值
    // c.show();
    // c1.show();
    //c1.operator<<(std::cout)
    // c1<<std::cout;
    
    //本质operator<<(std::cout<<c1,c1);
    // std::cout<<c1;
    //本质operator<<(operator<<(std::cout<<c1,c1),c2);
    // std::cout<<c1<<c2;

    Complex c;
    std::cin>>c;
    std::cout<<c;
    


    return 0;
}